//
//  PremiumExplainView.swift
//  XiaohuijiVPN
//
//  Created by topnet on 2022/9/28.
//

import UIKit
import YYText
import Lottie
class PremiumExplainView: ICBaseView {

    override func _initUI() {
        animationViewLayer = AnimationView()
        lbl1 = UILabel()
        lbl1.textColor = .theme
        lbl1.font = .font(20, weight: .bold)
        
        lbl2 = YYLabel()
        lbl2.numberOfLines = 0
        da.addSubviews(sub: [lbl1, lbl2])
    }
    
    override func _initData() {
        
        lbl1.text = "高级套餐"
        
        let t1 = "大量服务器，高速带宽\n没有使用和时间限制\n安全加密您的连接\n可同时使用五台设备\n无广告".text(font: .font(16), color: .black)
        t1.yy_lineSpacing = 5
        t1.yy_minimumLineHeight = 30
        
        lbl2.attributedText = t1
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        animationViewLayer.left_right(self).top(0).height(360.adapter)
        lbl1.left_right_offsetTop(animationViewLayer, margin: 30.adapter, x: 10.adapter).height(35.adapter)
        lbl2.left_right_offsetTop(lbl1).bottom(bounds.height)
    }
    
    override func didMoveToSuperview() {
        play(animation: "premium")
    }
    
    func play(animation: String) {
        let animation = Animation.named(animation, subdirectory: "lottie")
        self.animationViewLayer.animation = animation
        self.animationViewLayer.layer.masksToBounds = true
        self.animationViewLayer.contentMode = .scaleAspectFit
        self.addSubview(self.animationViewLayer)
        self.animationViewLayer.autoPinEdgesToSuperviewEdges()
        self.backgroundColor = .clear
        self.animationViewLayer.play()
        self.animationViewLayer.loopMode = .loop
        self.animationViewLayer.backgroundBehavior = .pauseAndRestore
    }

    private var animationViewLayer: AnimationView!
    private var lbl1: UILabel!
    private var lbl2: YYLabel!
}
